package com.example.bes008.single.ds.demo.controller;

import com.example.bes008.single.ds.demo.mapper.UserMapper;
import com.example.bes008.single.ds.demo.model.User;
import com.example.bes008.single.ds.demo.model.User2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@RestController
public class TestController {

    private static final Logger log = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private UserMapper userMapper;

    @GetMapping
    public String test() {
        return "SUCCESS";
    }

    /**
     * 插叙所有用户数据
     *
     * @return
     */
    @GetMapping(value = "/user/all")
    public List<User> selectAll() {
        return userMapper.selectUserList();
    }

    @Autowired
    DataSource dataSource;
    @GetMapping(value = "time")
    public Object get() throws SQLException {
        Connection connection = dataSource.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement("select * from muser2");
        ResultSet resultSet = preparedStatement.executeQuery();
        log.info("{}", resultSet);

        List<User2> users = userMapper.selectUserList2();
        log.info("");
        return null;
    }
}
